package com.cqeec.gams.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.cqeec.gams.entity.Account;
import com.cqeec.gams.service.AccountService;

@Controller
@RequestMapping("/app/")
public class MainController {
	@Autowired
	private AccountService accountService;

	@RequestMapping("/main.html")
	public ModelAndView gotoMainPage(HttpSession session) {
		ModelAndView mav = new ModelAndView("main");
		// 根据用户的角色查询相应的功能
		Object obj = session.getAttribute("account");
		if (obj == null) {
			// 没有登录
			mav.setViewName("redirect:/login.html");
		} else {
			Account account = (Account) obj;
			mav.addObject("functions", accountService.getFunction(account.getId()));
		}
		return mav;
	}
}
